package com.google.android.apps.iosched.util;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Build;

import com.google.android.apps.iosched.ui.phone.MapActivity;
import com.google.android.apps.iosched.ui.phone.SessionDetailActivity;
import com.google.android.apps.iosched.ui.phone.SessionsActivity;
import com.google.android.apps.iosched.ui.phone.TrackDetailActivity;
import com.google.android.apps.iosched.ui.phone.VendorDetailActivity;
import com.google.android.apps.iosched.ui.tablet.MapMultiPaneActivity;
import com.google.android.apps.iosched.ui.tablet.SessionsVendorsMultiPaneActivity;

import java.util.TimeZone;

/**
 * Created by Alex on 13-11-29.
 */
public class UIUtils {


    // 举办大会所在地的当地时间
    public static final TimeZone CONFERNCE_TIME_ZONE = TimeZone.getTimeZone("America/Los_Angeles");

    public static final long CONFERENCE_START_MILLIS = ParserUtils.parseTime("2012-06-27T09:30:00.000-07:00");
    public static final long CONFERENCE_END_MILLIS  = ParserUtils.parseTime("2012-06-29T18:00:00.000-07:00");

    public static final String CONFERENCE_HASHTAG = "#io12";

    private static final int SECOND_MILLIS = 1000;
    private static final int MINUTE_MILLIS = 60 * SECOND_MILLIS;
    private static final int HOUR_MILLIS = 60 * MINUTE_MILLIS;
    private static final int DAY_MILLIS = 24 * HOUR_MILLIS;



    /**
     * 返回当前的设备是否支持 "com.google.android.tv"
     * @param context
     * @return
     */
    public static boolean isGoogleTv(Context context){
        return context.getPackageManager().hasSystemFeature("com.google.android.tv");
    }


    private static final Class[] sPhoneActivities = new Class[]{
            MapActivity.class,
            SessionDetailActivity.class,
            SessionsActivity.class,
            TrackDetailActivity.class,
            VendorDetailActivity.class,
    };

    private static final Class[] sTabletActivities = new Class[]{
            MapMultiPaneActivity.class,
            SessionsVendorsMultiPaneActivity.class,
    };

    /**
     * 启用和禁用一些activity
     * @param context
     */
    public static void enableDisableActivities(Context context){
        boolean isHoneycombTablet = isHoneycombTablet(context);

        PackageManager pm = context.getPackageManager();

        for (Class a :sPhoneActivities){
            pm.setComponentEnabledSetting(new ComponentName(context,a)
                    ,isHoneycombTablet
                     ?PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                     :PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    ,PackageManager.DONT_KILL_APP);
        }

        for (Class a:sTabletActivities){
            pm.setComponentEnabledSetting(new ComponentName(context,a)
                     ,isHoneycombTablet
                      ?PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                      :PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                     ,PackageManager.DONT_KILL_APP);
        }
    }

    public static boolean isHoneycombTablet(Context context){
        return hasHoneycomb() && isTablet(context);
    }

    /**
     *
     * @param context
     * @return
     */
    public static boolean isTablet(Context context){
        return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
                >= Configuration.SCREENLAYOUT_SIZE_LARGE;
    }
    /**
     * 以下这些方法都是为了判断android的系统版本 依次是2.3 ,3.0, 3.1, 4.0, 4.1.
     * Build除了有版本信息还有一下硬件信息
     * @return
     */

    public static boolean hasFroyo() {
        // Can use static final constants like FROYO, declared in later versions
        // of the OS since they are inlined at compile time. This is guaranteed behavior.
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
    }
    public static boolean hasGingerbread() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD;
    }

    public static boolean hasHoneycomb() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
    }

    public static boolean hasHoneycombMR1() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1;
    }

    public static boolean hasICS() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
    }

    public static boolean hasJellyBean() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
    }
}
